﻿@{
    var Username = "";
    var isAdmin = "False";
    var isDeleted = "False";
    try{
        Username = Session["u.Username"].ToString();
        isAdmin = Session["u.isAdmin"].ToString();
    }catch{
        Username = "";
        isAdmin = "";
    }
   
    var db = Database.Open("CvProjectDatabase");
    var selectQuery = "Select * from Users Where Username like @0";

    var user = db.QuerySingle(selectQuery, Username);
    var selectApp = "Select Applicants.AppId, FirstName, LastName, CreationDate, PracticalScore,TheoreticalScore, Notes ,Name as Tags, Applicants.isDeleted FROM Applicants LEFT JOIN HistoryEntry ON Applicants.AppId = HistoryEntry.AppId LEFT JOIN Tags  ON Applicants.AppId = Tags.AppId where Applicants.isDeleted = 'False'";
    
    var searchTerm = "";
    var st = "";

    if(!Request.QueryString["searchTags"].IsEmpty() ) {
        selectApp = "Select Applicants.AppId, FirstName, LastName, CreationDate, PracticalScore,TheoreticalScore,Notes, Name as Tags, Applicants.isDeleted FROM Applicants LEFT JOIN HistoryEntry ON Applicants.AppId = HistoryEntry.AppId LEFT JOIN Tags  ON Applicants.AppId = Tags.AppId where Applicants.isDeleted = 'False' and Name LIKE @0";
        searchTerm = "%" + Request["searchTags"] + "%".ToString();
        searchTerm.Split(',');
    }
    var selectData = db.Query(selectApp, searchTerm);

    var grid = new WebGrid(source: selectData, defaultSort: "AppId", rowsPerPage:5);

}

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="res/css/bootstrap.min.css" rel="stylesheet">
    <link href="res/css/tableStyles.css" rel="stylesheet">
    <link href="res/css/bootstrap-tagsinput.css" rel="stylesheet">
   

  </head>
  <body>
   
     @if(Username.IsEmpty() || Username == ""){
            Response.Redirect("Login.cshtml"); 
     }


       <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                 <ul id="navigacija" class="nav navbar-nav">
                     <li style="margin-right: 30px"><a href="Index.cshtml"><b style="font-size: 1.7em">CV Database</b></a></li>


                     @if(isAdmin.Equals("True")){
                        <li style="font-size: 1.2em"><a href="UserAdministration.cshtml">User Administration</a></li>
                     }
                     <li style="font-size: 1.2em">@(user.FirstName + " " + user.LastName)</li>
                     <li style="padding-top: 15px"> | </li>
                   
                    
                        <li class="dropdown" style="font-size: 1.2em">
                        
                            
                            <li style="font-size: 1.2em"><a href="Login.cshtml?izlogujSe=true">Logout</a></li>
                        </ul>
                    </li>
                    
                 </ul>
            </div>
        </nav>
    <form method="get">
        <div>
            <label for="searchTags">Search for tags:</label>
            <input type="text" data-role="tagsinput" name="searchTags" value="" />
            <input type="Submit" value="Search" /><br/>
        </div>      
    </form>

        @grid.GetHtml(
                      tableStyle: "grid",
                     headerStyle: "head",
                     alternatingRowStyle: "alt",
                     columns: grid.Columns(
                     grid.Column("AppId"),
                     grid.Column("FirstName"),
                     grid.Column("LastName"),
                     grid.Column("CreationDate"),
                     grid.Column("PracticalScore"),
                     grid.Column("TheoreticalScore"),
                     grid.Column("Tags"),
                     grid.Column(format: @<a href="~/ApplicantsAdministration?edit=true&AppId=@item.AppId&FirstName=@item.FirstName&LastName=@item.LastName&PracticalScore=@item.PracticalScore&TheoreticalScore=@item.TheoreticalScore&Tags=@item.Tags&notes=@item.Notes">Edit</a>),
                     grid.Column(format: @<a href="~/Details?details=true&AppId=@item.AppId&FirstName=@item.FirstName&LastName=@item.LastName&PracticalScore=@item.PracticalScore&TheoreticalScore=@item.TheoreticalScore&name=@item.Tags&notes=@item.Notes">Details</a>)
                 )
             )

    
       
        <div>
            <input type="button" value="Add Applicant" onclick="location.href='ApplicantsAdministration.cshtml'"/>
        </div>
    



    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="res/js/bootstrap.min.js"></script>
    <!-- Tags -->
    <script src="res/js/bootstrap-tagsinput.js"></script>
    <script src="res/js/bootstrap-tagsinput.min.js"></script>
    <script src="res/js/bootstrap-tagsinput-angular.js"></script>
    <script src="res/js/bootstrap-tagsinput-angular.min.js"></script>

  </body>
</html>